****************************************************************************
****************************************************************************
** Code for replicating analyses in Allison Harell and Evan Lieberman,
** How Information about Race-based Health Disparities Affects Policy
** Preferences: Evidence from a Survey Experiment About the Covid-19 Pandemic
** in the United States
**
** Appearing in Social Science & Medicine
** https://doi.org/10.1016/j.socscimed.2021.113884
**
****************************************************************************
****************************************************************************



// Set YOUR directory to current folder and create an OUTPUT folder within that folder

// Main article tables will output as .rtf files; main article as .png files

// Supplement tables will output as .tex files; supplement figures as .png files, all beginging with "s"

// All other output is intermediary to produce final figures


use "repdata_harell_lieberman_ssm.dta"

cd OUTPUT

********************************************************************
****** FIGURE 2: Black vs White Estimates of COVID Death Rates ******
********************************************************************

*Numbers reported in text
tab White Underestimate, row
regress PriorDifference i.Black
margins Black

regress PriorDifference BlackAffect if White==1

*Figure 2
scatter Prior_Whites Prior_Blacks if Underestimate==0 & White==1, msymbol(o) mcolor(blue%30) scheme(s1mono) title(" ", size(small)) xtitle("Black American Death Rate") ytitle("White American Death Rate") xsize(3) ysize(3) || scatter Prior_Whites Prior_Blacks if Underestimate==0 & White==0, mcolor(blue%70) msymbol(t) || scatter Prior_Whites Prior_Blacks if Underestimate==1 & White==1, mcolor(red%30) msymbol(o) || scatter Prior_Whites Prior_Blacks if Underestimate==1 & White==0, mcolor(red%70) msymbol(t) ||  scatteri 54 54 (4) "Default", mcolor(black) msymbol(D) mlabcolor(black)   || scatteri 35 85 (3) "Actual", mcolor(black) msymbol(D) mlabcolor(black) legend(off)

graph export figure2.png, replace

	
*******************************
****** ANALYSIS 1 : RISK *******
*******************************


*All: Column 1
reg RiskScale Information##Black PriorsAsked Woman CatAge University ln_StateDeaths if Covid_b==0 & Treat!=2
estimates store RiskScale

* Blacks: Column 2

reg RiskScale Information##Underestimate Woman CatAge University ln_StateDeaths if Covid_b==0 & Treat!=1 & Treat!=2 & Black==1
estimates store RiskScale_blackunder

margins, dydx(Information) at(Underestimate=(0 1)) 
marginsplot, title("", size(small)) scheme(s1mono) yline(0, lcolor(red)) xtitle("Prior Knowledge of Racial Disparities", size(small)) xlabel(,labsize(small)) xsc(r(-.1 1.1))

graph export figure3.png, replace


* Whites: Column 3
reg RiskScale Information##Underestimate PriorsAsked Woman CatAge University ln_StateDeaths if Covid_b==0 & White==1 & Treat!=1
estimates store RiskScale_whiteunder
margins, dydx(Information) at(Underestimate=(0 1))

* Whites: Column 4 Black Affect
regress  RiskScale Information##c.BlackAffect PriorsAsked##Information Woman CatAge University ln_StateDeaths if Covid_b==0  & White==1
estimates store RiskScale_whiteaffect

margins, dydx(Information) at(BlackAffect=(0(25)100))
marginsplot, title("", size(small)) scheme(s1mono) yline(0, lcolor(red)) xtitle("Feeling Thermometer Towards Blacks", size(small))
graph export figure4.png, replace
	

**Table 2: Note RTF output / manual adjustment for formatting to get PriorsAsked aligned in col4
	esttab RiskScale RiskScale_blackunder RiskScale_whiteunder RiskScale_whiteaffect using table2.rtf ,  nobaselevels order (1.Information 1.Black 1.Information#1.Black 1.Underestimate 1.Information#1.Underestimate BlackAffect 1.Information#c.BlackAffect Woman CatAge University ln_StateDeaths PriorsAsked) coeflabels (1.Information "Information" 1.Black "Black" 1.Information#1.Black "Information*Black" 1.Underestimate "Underestimate" 1.Information#1.Underestimate "Information*Underestimate" BlackAffect "BlackAffect" 1.Information#c.BlackAffect "Information*BlackAffect" Woman "Woman" CatAge "Age" University "University" ln_StateDeaths "logStateDeaths" PriorsAsked "PriorsAsked" 1.PriorsAsked#1.Information "PriorsAsked*Information") mtitles("All" "Blacks" "Whites" "Whites") ///
    starlevels(* .05 ** .01 *** .001) ///
    stats(N) interaction("$\times$ ") style(tex) title("Estimated Treatment Effects of Disparity Information on Risk Perception By Race Group") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001" "Models 1 and 2 exclude treatment arm 2 because no black respondents" "Models 2 and 3 exclude treatment arm 1 because no information about prior beliefs") replace
	
	
*******************************************************
****** ANALYSIS 2 : BLACK POLICY PREFERENCES *******
*******************************************************

foreach var of varlist  CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	reg `var' Information##Underestimate Woman CatAge University ln_StateDeaths if Black==1
	estimates store H4_`var'
	

}

	esttab H4_CombatScale H4_Pub_Health_Scale H4_Liberty_Scale H4_CovidReliefScale using table3.rtf ,  nobaselevels  order (1.Information 1.Underestimate 1.Information#1.Underestimate Woman CatAge University ln_StateDeaths) ///
	coeflabels (1.Information "Information" 1.Underestimate "Underestimate" 1.Information#1.Underestimate "Information*Underestimate" Woman "Woman" CatAge "Age" University "University" ln_StateDeaths "logStateDeaths") ///
    starlevels(* .05 ** .01 *** .001) ///
    stats(N) interaction("$\times$ ") style(tex) title("Estimated Treatment Effects of Disparity Information on Policy Preferences, Black Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001") replace
	

********************************************************
****** ANALYSIS 3 : WHITE POLICY PREFERENCES *******
********************************************************


** All Whites (Columns 1-4)
	
foreach var of varlist CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale  {
	
	reg `var' Information##c.BlackAffect Information#PriorsAsked Woman CatAge University ln_StateDeaths if White==1
	estimates store H1_cont_`var'
	margins, dydx(Information) at(BlackAffect=(0(25)100)) saving(H1_`var'_marg,replace)
 	marginsplot, title("`var'") yline(0, lcolor(red)) scheme(s1mono) saving(H1_`var'.gph, replace) 
}	

// Figure 1 in supplemental materials
graph combine H1_CombatScale.gph H1_Pub_Health_Scale.gph H1_Liberty_Scale.gph H1_CovidReliefScale.gph, title("", size(small)) col(2) altshrink xsize(4) ysize(4) scheme(s1mono) saving(Figure2.gph, replace)
graph export sfigure1.png, replace


** White underestimators (Columns 5-8)


foreach var of varlist CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	reg `var' Information##c.BlackAffect PriorsAsked Woman CatAge University ln_StateDeaths if White==1 & (Treat==0 | Treat==2 | Treat==3) & Underestimate==1
	estimates store H3_`var'
	margins, dydx(Information) at(BlackAffect=(0(25)100)) saving(H3_`var'_marg,replace)
	estimates store H3_`var'_margin

marginsplot, title("`var'") scheme(s1mono) yline(0, lcolor(red)) saving(H3_`var'.gph, replace) 
}

graph combine H3_CombatScale.gph H3_Pub_Health_Scale.gph H3_Liberty_Scale.gph H3_CovidReliefScale.gph, title("", size(small)) col(2) altshrink xsize(4) ysize(4) scheme(s1mono) saving(Figure3.gph, replace)

graph export figure5.png, replace
	
	
*** Combined 8-column for Table 4
	
		esttab H1_cont_CombatScale H1_cont_Pub_Health_Scale  H1_cont_Liberty_Scale  H1_cont_CovidReliefScale  H3_CombatScale H3_Pub_Health_Scale H3_Liberty_Scale H3_CovidReliefScale using table4.rtf , drop (0.Information 0.Information#c.BlackAffect 0.Information#0.PriorsAsked 1.Information#0.PriorsAsked)  order (1.Information BlackAffect 1.Information#c.BlackAffect 0.Information#1.PriorsAsked 1.Information#1.PriorsAsked Woman CatAge University ln_StateDeaths ) ///
		coeflabels (1.Information "Information" BlackAffect "BlackAffect" 1.Information#c.BlackAffect "Information*BlackAffect" 0.Information#1.PriorsAsked "PriorsAsked" 1.Information#1.PriorsAsked "Information*PriorsAsked" Woman "Woman" CatAge "Age" University "University" ln_StateDeaths "logStateDeaths" ) ///
    starlevels(* .05 ** .01 *** .001) ///
    stats(N) interaction("$\times$ ") style(tex) title("Estimated Treatment Effects of Disparity Information on Policy Preferences, White Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001") replace
	
	
** Benjamini-Hochberg correction

// Note, we used the shinyapp located here https://egap.shinyapps.io/multiple-comparisons-app/
	
	
**********************************************************
****** OTHER FOR SUPPLEMENTARY APPENDIX *******************
**********************************************************


***************************************
****** Summary Statistics	 **********
***************************************	

summarize RiskScale CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale White Prior_White Prior_Black PriorDifference Underestimate BlackAffect  Woman CatAge University ln_StateDeaths

estpost summarize RiskScale CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale White Prior_White Prior_Black PriorDifference Underestimate BlackAffect  Woman CatAge University ln_StateDeaths

esttab using stable1.tex, cells("count mean sd min max") noobs title("Summary Statistics") replace



***************************************
****** Balance Tables    	 **********
***************************************	
	
	
gen Treat23=.
replace Treat23=1 if Group=="Treatment2"
replace Treat23=2 if Group=="Treatment3"
replace Treat23=0 if Group=="Control" 
* Create 1 and 3 treatment for Blacks 
gen treat13=.
replace treat13=2 if Group=="Treatment3"
replace treat13=1 if Group=="Treatment1"
replace treat13=0 if Group=="Control"


*Recall no Blacks in Priors Only arm

iebaltab Woman CatAge University Republican BlackAffect if White==1, grpvar("Treat")  replace  savetex ("stable2.tex")
iebaltab Woman CatAge University Republican  if Black==1, grpvar("Treat")  replace savetex("stable3.tex")

iebaltab Underestimate if White==1, grpvar("Treat23")  replace savetex("stable4.tex")
iebaltab Underestimate if Black==1, grpvar("Treat23")  replace savetex("stable5.tex")



**********************************************************************
****** Models of treatment effects with no controls ******************
**********************************************************************

foreach var of varlist  CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	
	reg `var' Information##PriorsAsked if White==1
	estimates store baseW_`var'
}

	reg RiskScale Information##PriorsAsked if Covid_b==0  & White==1
	estimates store baseW_RiskScale


foreach var of varlist  CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	
	reg `var' i.Treat if White==0 & Treat!=2
	estimates store baseB_`var'
}
	reg RiskScale i.Treat if Covid_b==0  & White==0 & Treat!=2
	estimates store baseB_RiskScale


esttab baseW_CombatScale baseW_Pub_Health_Scale baseW_Liberty_Scale baseW_CovidReliefScale baseW_RiskScale using stable6.tex  , starlevels(* .05 ** .01 *** .001) ///
    stats(N) nobaselevels  order (1.Information 1.Information#1.PriorsAsked 1.PriorsAsked) ///
				coeflabels (1.Information "Information" 1.Information#1.PriorsAsked "Information*PriorsAsked" 1.PriorsAsked "PriorsAsked") ///
   style(tex) title("Base Models with No Additional Controls" "White Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001") replace
	
esttab baseB_CombatScale baseB_Pub_Health_Scale baseB_Liberty_Scale baseB_CovidReliefScale baseB_RiskScale using stable7.tex  , starlevels(* .05 ** .01 *** .001) order (1.Treat 3.Treat) ///
				coeflabels (1.Treat "Information" 3.Treat "Information*PriorsAsked") ///
    stats(N) nobaselevels  style(tex) title("Base Models with No Additional Controls, Black Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001") replace
	
		
	
	
*********************************************************************
****** Does Priming (PriorsAsked) Have Treatment Effect? **********
*********************************************************************

//Whites Affect
foreach var of varlist CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	reg `var' Treat##c.BlackAffect Woman CatAge University ln_StateDeaths if White==1
	estimates store H2_cont_`var'
}	


//Whites Affect for Underestimators
foreach var of varlist CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	reg `var' Treat##c.BlackAffect Woman CatAge University ln_StateDeaths if White==1 & CorrectEstimate==0
	estimates store H2_under_`var'
}


//Whites Affect for Correct Estimators
foreach var of varlist CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	reg `var' Treat##c.BlackAffect Woman CatAge University ln_StateDeaths if White==1 & CorrectEstimate==1
	estimates store H2_correct_`var'
}


			esttab H2_cont_CombatScale H2_cont_Pub_Health_Scale H2_cont_Liberty_Scale H2_cont_CovidReliefScale using stable8.tex , starlevels(* .05 ** .01 *** .001) nobaselevels /// 
    stats(N) interaction("$\times$ ") style(tex) title("Estimates of Various Treatment Arms Conditional on Black Affect, All White Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001") ///		
		coeflabels (1.Treat "Information" 2.Treat "PriorsAsked" 3.Treat "Priors+Information" BlackAffect "BlackAffect" 1.Treat#c.BlackAffect "Information*BlackAffect" 2.Treat#c.BlackAffect "Priors*BlackAffect" 3.Treat#c.BlackAffect "(Priors+Infor)*BlackAffect" Woman "Woman" CatAge "Age" University "University" ln_StateDeaths "logStateDeaths" ) replace 
    
	
		esttab H2_under_CombatScale H2_under_Pub_Health_Scale H2_under_Liberty_Scale H2_under_CovidReliefScale using stable9.tex , starlevels(* .05 ** .01 *** .001) nobaselevels /// 
    stats(N) interaction("$\times$ ") style(tex) title("Estimates of Various Treatment Arms Conditional on Black Affect, Under-Estimator White Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001") ///		
		coeflabels (1.Treat "Information" 2.Treat "PriorsAsked" 3.Treat "Priors+Information" BlackAffect "BlackAffect" 1.Treat#c.BlackAffect "Information*BlackAffect" 2.Treat#c.BlackAffect "Priors*BlackAffect" 3.Treat#c.BlackAffect "(Priors+Infor)*BlackAffect" Woman "Woman" CatAge "Age" University "University" ln_StateDeaths "logStateDeaths" ) replace 
    

		esttab H2_correct_CombatScale H2_correct_Pub_Health_Scale H2_correct_Liberty_Scale H2_correct_CovidReliefScale using stable10.tex , starlevels(* .05 ** .01 *** .001) nobaselevels /// 
    stats(N) interaction("$\times$ ") style(tex) title("Estimates of Various Treatment Arms Conditional on Black Affect, Correct Estimator White Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001") ///		
		coeflabels (1.Treat "Information" 2.Treat "PriorsAsked" 3.Treat "Priors+Information" BlackAffect "BlackAffect" 1.Treat#c.BlackAffect "Information*BlackAffect" 2.Treat#c.BlackAffect "Priors*BlackAffect" 3.Treat#c.BlackAffect "(Priors+Infor)*BlackAffect" Woman "Woman" CatAge "Age" University "University" ln_StateDeaths "logStateDeaths" ) replace 
    


***************************************
****** OBSERVATIONAL ANALYSES    ******
***************************************

// note that CorrectEstimate is just inverse of Underestimate. see description in text

foreach var of varlist  CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{

	reg `var' CorrectEstimate##c.BlackAffect Woman CatAge University ln_StateDeaths if White==1 & (Treat==0 | Treat==2)
	estimates store H1_obs_`var'
		margins, dydx(CorrectEstimate) at(BlackAffect=(0(25)100))
	marginsplot, title("`var'") scheme(s1mono) yline(0, lcolor(red))  saving(H1obs_`var'.gph, replace) 

}


	
esttab H1_obs_CombatScale H1_obs_Pub_Health_Scale H1_obs_Liberty_Scale H1_obs_CovidReliefScale using stable11.tex  ,  nobaselevels coeflabels (1.CorrectEstimate "Correct Estimate" BlackAffect "Black Affect" 1.CorrectEstimate#c.BlackAffect "Correct Est*Black Affect" Woman "Woman" CatAge "Age" University "University" ln_StateDeaths "logStateDeaths") ///
    starlevels(* .05 ** .01 *** .001) ///
    stats(N) interaction("$\times$ ") style(tex) title("Predictive Associations With Correct Information Moderated by Affect" "White Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001") replace
	

	

	
***************************************
****** Partisanship			 **********
***************************************	

mean BlackAffect, over(partisanship)
corr Democrat BlackAffect ResentScale if White==1

*******Models from paper, but controlling for  PID ********	

regress  RiskScale Information##c.BlackAffect Information#PriorsAsked i.partisanship Woman CatAge University ln_StateDeaths if Covid_b==0  & White==1
estimates store pid_RiskScale
	
margins, dydx(Information) at(BlackAffect=(0(25)100))
marginsplot, title("`var'", size(small)) scheme(s1mono) yline(0, lcolor(red)) 

graph export sfigure2.png, replace


foreach var of varlist  CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	
	reg `var' Information##c.BlackAffect Information#PriorsAsked i.partisanship Woman  CatAge University ln_StateDeaths if White==1
	estimates store pid_`var'
margins, dydx(Information) at(BlackAffect=(0(25)100))
marginsplot, title("`var'", size(small))  scheme(s1mono) yline(0, lcolor(red)) saving(pid_`var'.gph, replace) 
}
graph combine pid_CombatScale.gph pid_Pub_Health_Scale.gph pid_Liberty_Scale.gph pid_CovidReliefScale.gph, title("", size(small)) col(2) altshrink xsize(4) ysize(4) scheme(s1mono) saving(pid.gph, replace)

graph export sfigure3.png, replace


***
		esttab pid_RiskScale pid_CombatScale pid_Pub_Health_Scale pid_Liberty_Scale pid_CovidReliefScale using stable12.tex ,   drop(0.Information 0.Information#c.BlackAffect 0.Information#0.PriorsAsked 1.Information#0.PriorsAsked 0.partisanship) ///
		coeflabels (1.Information "Information" BlackAffect "BlackAffect" 1.Information#c.BlackAffect "Information*BlackAffect" 0.Information#1.PriorsAsked "PriorsAsked" 1.Information#1.PriorsAsked "Information*PriorsAsked" 1.partisanship "Republican" 2.partisanship "Independent" Woman "Woman" CatAge "Age" University "University" ln_StateDeaths "logStateDeaths" ) ///
    starlevels(* .05 ** .01 *** .001) ///
    stats(N) interaction("$\times$ ") style(tex) title("Estimated Treatment Effects of Disparity Information on Policy Preferences Controlling for Partisan Identity, White Respondents") ///
	nonotes addnote ("* p$<$.05 **p$<$.01 ***p$<$.001" "Excluded Partisan category is Democrat") replace


***************************************************
****** Robustness to PriorDiff coding	 **********
***************************************************


reg RiskScale Information##c.PriorDifference PriorsAsked Woman CatAge University ln_StateDeaths if Covid_b==0 & White==1 & Treat!=1
margins, dydx(Information) at(PriorDifference=(-100(25)100)) 
marginsplot


reg RiskScale Information##c.PriorDifference Woman CatAge University ln_StateDeaths if Covid_b==0 & Treat!=1 & Treat!=2 & Black==1
margins, dydx(Information) at(PriorDifference=(-100(25)100)) 
marginsplot



// codings for underestimators, based on real PriorDifference Scores
// Using 0 (no difference, as baseline)
foreach var of varlist CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	reg `var' Information##c.BlackAffect PriorsAsked Woman CatAge University ln_StateDeaths if White==1 & (Treat==0 | Treat==2 | Treat==3) & PriorDifference<=0
	margins, dydx(Information) at(BlackAffect=(0(25)100))

	marginsplot, title("`var'") yline(0, lcolor(red)) scheme(s1mono) saving(rob1_`var'.gph, replace) 
}	

graph combine rob1_CombatScale.gph rob1_Pub_Health_Scale.gph rob1_Liberty_Scale.gph rob1_CovidReliefScale.gph, title("", size(small)) col(2) altshrink xsize(4) ysize(4) scheme(s1mono)
graph export sfigure4.png, replace


// Using below White mean (13) on Prior Difference
foreach var of varlist CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	reg `var' Information##c.BlackAffect PriorsAsked Woman CatAge University ln_StateDeaths if White==1 & (Treat==0 | Treat==2 | Treat==3) & PriorDifference<=13
	margins, dydx(Information) at(BlackAffect=(0(25)100))

	marginsplot, title("`var'") scheme(s1mono) yline(0, lcolor(red)) saving(rob2_`var'.gph, replace) 
}	

// Figure for Paper
graph combine rob2_CombatScale.gph rob2_Pub_Health_Scale.gph rob2_Liberty_Scale.gph rob2_CovidReliefScale.gph, title("", size(small)) col(2) altshrink xsize(4) ysize(4) scheme(s1mono) 
graph export sfigure5.png, replace


// Using actual difference plus or minus 5 (45) on Prior Difference
foreach var of varlist CombatScale Pub_Health_Scale Liberty_Scale CovidReliefScale{
	reg `var' Information##c.BlackAffect PriorsAsked Woman CatAge University ln_StateDeaths if White==1 & (Treat==0 | Treat==2 | Treat==3) & PriorDifference<=45
	margins, dydx(Information) at(BlackAffect=(0(25)100))

	marginsplot, title("`var'") scheme(s1mono) yline(0, lcolor(red)) saving(rob3_`var'.gph, replace) 
}	

// Figure for Paper
graph combine rob3_CombatScale.gph rob3_Pub_Health_Scale.gph rob3_Liberty_Scale.gph rob3_CovidReliefScale.gph, title("", size(small)) col(2) altshrink xsize(4) ysize(4) scheme(s1mono) 
graph export sfigure6.png, replace

